package com.lc.app.myaccount.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.lc.app.myaccount.R;
import com.lc.app.myaccount.dao.OutAccountDao;
import com.lc.app.myaccount.dao.UserDao;
import com.lc.app.myaccount.entity.OutAccount;
import com.lc.app.myaccount.entity.UserEntity;

import java.util.List;

public class MyOutAccountActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_out_account);
        TableLayout layout = (TableLayout) findViewById(R.id.layoutMyOutAccount);
        UserDao userDao = new UserDao(this);
        UserEntity user = userDao.findByName("admin");
        OutAccountDao dao = new OutAccountDao(this);
        List<OutAccount> list =dao.findByUserId(user.get_id());
        for(OutAccount out : list){
            TableRow tableRow = new TableRow(this);
            TextView tvMoney = new TextView(this);
            tvMoney.setText("金额："+out.getMoney()+"\t");

            TextView tvPlace = new TextView(this);
            tvPlace.setText("地点："+out.getAddress()+"\t");

            TextView tvType = new TextView(this);
            tvType.setText("类型："+out.getType()+"\t");

            TextView tvTime = new TextView(this);
            tvTime.setText("时间："+out.getTime()+"\t");

            tableRow.addView(tvMoney);
            tableRow.addView(tvPlace);
            tableRow.addView(tvType);
            tableRow.addView(tvTime);
            layout.addView(tableRow);
        }

    }
}
